<?php
require_once 'php-antlr/antlr.php';
require_once 'ExpLexer.php';
require_once 'ExpParser.php';

function parse_expr($in_expr) {
    
    $input  = new ANTLRStringStream($in_expr); // Expression string to parse
    $lexer  = new ExpLexer($input);            // Instantiate a lexer object
    $tokens = new CommonTokenStream($lexer);   // Generates a list of tokens
    $parser = new ExpParser($tokens);          // Parse the generated tokens  
    
    return $parser->compute();
}

$expr1 = "5*2";
$expr2 = "((100*5-3*(6/3))-1)/2";

echo parse_expr($expr1) . "\n";
echo parse_expr($expr2) . "\n";
?>